package com.yima.baseproj.module.app.teacher;

import com.yima.baseproj.module.config.utils.ResultUtil;
import com.yima.baseproj.module.config.utils.ResultVo;
import com.yima.baseproj.module.sys.clazz.ClassEntity;
import com.yima.baseproj.module.sys.clazz.ClassService;
import com.yima.baseproj.module.sys.teacher.TeacherEntity;
import com.yima.baseproj.module.sys.teacher.TeacherService;
import com.yima.baseproj.module.sys.teacher.clazz.TeacherClassEntity;
import com.yima.baseproj.module.sys.teacher.clazz.TeacherClassService;
import com.yima.baseproj.module.sys.teacher.model.TeacherSearchAddModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "小程序教师")
@RestController
@RequestMapping("/api/app/teacher")
public class AppTeacherController {

    @Autowired
    private TeacherService teacherService;

    @Autowired
    private AppTeacherService appTeacherService;

    @Autowired
    private TeacherClassService teacherClassService;

    @Autowired
    private ClassService classService;
    /**
     * 根据 code 查询教师信息
     * @param teacherCode
     * @return
     */
    @GetMapping("/findByCode/{teacherCode}")
    public TeacherSearchAddModel findByCode(@PathVariable String teacherCode){
        return appTeacherService.findByCode(teacherCode);
    }

    @GetMapping("/findByVxId/{teacherVxId}")
    public TeacherEntity findByVxId(@PathVariable String teacherVxId){
        return appTeacherService.findByOpenId(teacherVxId);
    }
    /**
     * 前端小程序传的教师 微信id(就是openid) 微信名 微信头像
     * @param customAdmin
     */
    @PostMapping("/update")
    public void update(@RequestBody TeacherEntity customAdmin) {
        teacherService.updateById(customAdmin);
    }


    @ApiOperation("根据教师id 查询班级列表")
    @GetMapping("/findClassListByTeacherId/{teacherId}")
    public ResultVo findClassListByKgId(@PathVariable int teacherId) {
        List<ClassEntity> classList = teacherClassService.getTeacherClass(teacherId);
        return ResultUtil.success(classList);
    }


}
